package com.bestv.search.common.service.impl;

import com.bestv.search.common.dao.NetInfoReviewDao;
import com.bestv.search.common.dataSource.DataSourceKey;
import com.bestv.search.common.model.NetInfoReview;
import com.bestv.search.common.model.uid.UID;
import com.bestv.search.common.service.NetInfoReviewManager;

import java.util.List;

public class NetInfoReviewManagerImpl implements NetInfoReviewManager {
    private NetInfoReviewDao netInfoReviewDao;

    @Override
    public void saveOrUpdateList(DataSourceKey key, List<NetInfoReview> list) {
        for (NetInfoReview review : list) {
            NetInfoReview reviewInDB = netInfoReviewDao.getByReviewId(review.getReviewId(), review.getSource());
            // Save un-exist comment in to DB
            if (reviewInDB == null) {
                review.setId(new Long(UID.getUID(review)));
                netInfoReviewDao.saveOrUpdate(review);
            }
        }
    }

    @Override
    public List<NetInfoReview> getNetInfoReviewsByNetInfoId(DataSourceKey key, long netInfo_id, int start, int limit) {
        return netInfoReviewDao.getNetInfoReviewsByNetInfoId(netInfo_id, start, limit);
    }

    @Override
    public int getReviewsCountByNetInfoId(DataSourceKey key, long netInfo_id) {
        return netInfoReviewDao.getReviewsCountByNetInfoId(netInfo_id);
    }

    public NetInfoReviewDao getNetInfoReviewDao() {
        return netInfoReviewDao;
    }

    public void setNetInfoReviewDao(NetInfoReviewDao netInfoReviewDao) {
        this.netInfoReviewDao = netInfoReviewDao;
    }
}